# Object with movements, has position, size and speed

class Object(object):
    def __init__(self, position_x, position_y):
        # Position
        self.starting_position_x = position_x
        self.starting_position_y = position_y

        self.position_x = position_x
        self.position_y = position_y 
        self.speed_x = 0
        self.speed_y = 0

    def __init__(self, position_x, position_y, speed_x, speed_y):
        # Position and speed
        self.starting_position_x = position_x
        self.starting_position_y = position_y
        
        self.position_x = position_x
        self.position_y = position_y
        self.speed_x = speed_x
        self.speed_y = speed_y	

    def __init__(self, position_x, position_y, speed_x, speed_y, width, height):
        # Position, speed and size
        self.starting_position_x = position_x
        self.starting_position_y = position_y
        
        self.position_x = position_x
        self.position_y = position_y
        self.speed_x = speed_x
        self.speed_y = speed_y
        self.width = width
        self.height = height

    # Setters
    def set_position(self, position_x, position_y):
        self.position_x = position_x
        self.position_y = position_y

    def setSpeed(self, speed_x, speed_y):
        self.speed_x = speed_x
        self.speed_y = speed_y	 

    def setLimits(self, limit_x, limit_y, width, height):
        self.limit_x = limit_x
        self.limit_y = limit_y
        self.limit_width = width
        self.limit_height = height

    # Getters			
    def getPosition(self):
        rect = [self.position_x, self.position_y]
        return (rect)

    def getSpeed(self):
        rect = [self.speed_x, self.speed_y]
        return (rect)

    def getRect(self):
        rect = [self.position_x, self.position_y, self.width, self.height]
        return (rect)

    def getLimits(self):
        rect = [self.limit_x, self.limit_y, self.limit_width, self.limit_height]
        return (rect)

    # Modifiers
    def increaseSpeed(self, speed_x, speed_y):
        self.speed_x += speed_x
        self.speed_y += speed_y

    def updatePosition(self):
        self.position_x += self.speed_x
        self.position_y += self.speed_y

    def reset(self):
        self.position_x = self.starting_position_x
        self.position_y = self.starting_position_y
        self.speed_x = 0
        self.speed_y = 0

    # Aux
    def inRangeX(self):
        new_position = self.position_x
        rect = self.getLimits()
        limit_x = rect[0]
        width = rect[2]
        if self.position_x < limit_x:
            new_position = limit_x
        if self.position_x > limit_x + width - self.width:
            new_position = limit_x + width - self.width
        return new_position
        
    def inRangeY(self):
        new_position = self.position_y
        rect = self.getLimits()
        limit_y = rect[1]
        height = rect[3]
        if self.position_y < limit_y:
            new_position = limit_y
        if self.position_y > limit_y + height - self.height:
            new_position = limit_y + height - self.height
        return new_position
        
    def inRange(self):        
        return [inRangeX(self), inRangeY(self)]
